package com.cskaoyan.service;

import com.cskaoyan.bean.MarketLog;
import com.cskaoyan.bean.MarketLogExample;
import com.cskaoyan.mapper.MarketLogMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.cskaoyan.util.StringUtil;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @Author：LiuFan
 * @Project：first-project
 * @Package：com.cskaoyan.service
 * @Date：2023/5/31 15:14
 */
public class AdminLogServiceImpl implements AdminLogService {

    SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
    @Override
    public List<MarketLog> list(String name, Integer page, Integer limit, String sort, String order) {

        MarketLogExample example = new MarketLogExample();
        MarketLogExample.Criteria criteria = example.createCriteria();

        if (!StringUtil.isEmpty(name)){
            criteria.andAdminLike("%" + name + "%");
        }
        criteria.andDeletedEqualTo(false);
        if (!StringUtil.isEmpty(sort) && !StringUtil.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }
        PageHelper.startPage(page, limit);

        MarketLogMapper logMapper = sqlSessionFactory.openSession().getMapper(MarketLogMapper.class);

        return logMapper.selectByExample(example);
//        return CommonData.data(new PageInfo(marketLogs));
    }
}
